package com.smartleanx.module.hrm.controller.app.salary;

import com.alibaba.fastjson2.JSONObject;
import com.github.pagehelper.PageInfo;
import com.smartleanx.framework.common.pojo.CommonResult;
import com.smartleanx.module.hrm.dal.dataobject.salary.HrmSalaryFixed;
import com.smartleanx.module.hrm.dal.dataobject.salary.HrmSalaryPlan;
import com.smartleanx.module.hrm.dal.dataobject.salary.HrmSalaryTaxationRuleTenant;
import com.smartleanx.module.hrm.dal.dataobject.salary.HrmSalaryTemplate;
import com.smartleanx.module.hrm.dal.dataobject.salary.bo.HrmSalaryPlanInsertBo;
import com.smartleanx.module.hrm.dal.dataobject.salary.vo.FixedEmployeeVo;
import com.smartleanx.module.hrm.dal.dataobject.salary.vo.HrmSalaryPlanInsertVo;
import com.smartleanx.module.hrm.dal.dataobject.salary.vo.HrmSalaryTableConfigVo;
import com.smartleanx.module.hrm.dal.dataobject.salary.vo.HrmSalaryTaxationRuleVo;
import com.smartleanx.module.hrm.service.salary.HrmSalaryFixedService;
import com.smartleanx.module.hrm.service.salary.HrmSalaryRecordService;
import com.smartleanx.module.hrm.service.salary.HrmSalaryTableConfigService;
import com.smartleanx.module.hrm.service.salary.HrmSalaryTemplateService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "app后台 - 薪资 ")
@RestController
@RequestMapping("/hrm/salary")
public class SalaryAppController {
    @Autowired
    private HrmSalaryTableConfigService hrmSalaryTableConfigService;
    @Autowired
    private HrmSalaryFixedService salaryFixedService;
    @Autowired
    private HrmSalaryTemplateService salaryTemplateService;
    @Autowired
    private HrmSalaryRecordService salaryRecordService;


    @GetMapping("/selectConfigList")
    public CommonResult<Object> selectConfigList(@RequestParam("type") Integer type) {
        return CommonResult.success(hrmSalaryTableConfigService.selectList(type));
    }


    @GetMapping("/selectListConfigInfo")
    public CommonResult<Object> selectListConfigInfo(@RequestParam("type") Integer type) {
        return CommonResult.success(hrmSalaryTableConfigService.selectListInfo(type));
    }



    @PostMapping("/insertOrUpdateConfig")
    public CommonResult<Object> insertOrUpdateConfig(@RequestBody List<HrmSalaryTableConfigVo> hrmSalaryTableConfigVos) {
        return CommonResult.success(hrmSalaryTableConfigService.insertOrUpdate(hrmSalaryTableConfigVos));
    }
    /**
     * 计薪设置
     *
     * @param type
     * @return
     */
    @GetMapping("/salarySettingSaveOrUpdate")
    public CommonResult<Object> salarySettingSaveOrUpdate(@RequestParam("type") Integer type) {
        hrmSalaryTableConfigService.salarySettingSaveOrUpdate(type);
        return CommonResult.success("操作成功");
    }


    /**
     * 计薪设置
     *
     * @return
     */
    @GetMapping("/selectSetting")
    public CommonResult<Object> selectSetting() {
        Integer i = hrmSalaryTableConfigService.selectSetting();
        return CommonResult.success(i);
    }


    /**
     * 计税规则设置列表
     */
    @GetMapping("/selectTaxationRuleList")
    public CommonResult<Object> selectTaxationRuleList(@RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize) {
        PageInfo<HrmSalaryTaxationRuleVo> hrmSalaryTaxationRuleVoPageInfo = hrmSalaryTableConfigService.selectTaxationRuleList(pageNum, pageSize);
        return CommonResult.success(hrmSalaryTaxationRuleVoPageInfo);
    }


    /**
     * 计税规则设置新增或修改
     */
    @PostMapping("/InsertOrUpdateTaxationRule")
    public CommonResult<Object> InsertOrUpdateTaxationRule(@RequestBody HrmSalaryTaxationRuleTenant HrmSalaryTaxationRuleTenant) {
        hrmSalaryTableConfigService.insertOrUpdateTaxationRule(HrmSalaryTaxationRuleTenant);
        return CommonResult.success("操作成功");
    }


    /**
     * 计税规则下拉
     */
    @GetMapping("/taxationRuleBySelect")
    public CommonResult<Object> taxationRuleBySelect() {
        List<JSONObject> jsonObjectList = hrmSalaryTableConfigService.taxationRuleBySelect();
        return CommonResult.success(jsonObjectList);
    }


    /**
     * 计税规则编辑回显
     *
     * @param id
     * @return
     */
    @GetMapping("/selectTaxationRuleById")
    public CommonResult<Object> selectTaxationRuleById(@RequestParam("id") Integer id) {
        HrmSalaryTaxationRuleTenant HrmSalaryTaxationRuleTenant = hrmSalaryTableConfigService.selectTaxationRuleById(id);
        return CommonResult.success(HrmSalaryTaxationRuleTenant);
    }


    /**
     * 薪资组新增
     */
    @PostMapping("/insertSalaryPlan")
    public CommonResult<Object> insertSalaryPlan(@RequestBody HrmSalaryPlanInsertBo hrmSalaryPlanInsertBo) {
        Integer i = hrmSalaryTableConfigService.insertSalaryPlan(hrmSalaryPlanInsertBo);
        return CommonResult.success(i);
    }

    /**
     * 薪资组编辑
     */
    @PostMapping("/updateSalaryPlan")
    public CommonResult<Object> updateSalaryPlan(@RequestBody HrmSalaryPlanInsertBo hrmSalaryPlanInsertBo) {
        Integer i = hrmSalaryTableConfigService.updateSalaryPlan(hrmSalaryPlanInsertBo);
        return CommonResult.success(i);
    }

    /**
     * 薪资组列表
     */
    @GetMapping("/salaryPlanList")
    public CommonResult<Object> salaryPlanList(@RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize) {
        PageInfo<HrmSalaryPlanInsertVo> hrmSalaryPlanInsertVoPageInfo = hrmSalaryTableConfigService.salaryPlanList(pageNum, pageSize);
        return CommonResult.success(hrmSalaryPlanInsertVoPageInfo);
    }

    /**
     * 薪资组回显
     */
    @GetMapping("/selectSalaryPlanById")
    public CommonResult<Object> selectSalaryPlanById(@RequestParam("id") Integer id) {
        HrmSalaryPlan hrmSalaryPlanInsertVo = hrmSalaryTableConfigService.selectSalaryPlanById(id);
        return CommonResult.success(hrmSalaryPlanInsertVo);
    }


    /**
     * 删除薪资组
     */
    @GetMapping("/deletedSalaryPlan")
    public CommonResult<Object> deletedSalaryPlan(@RequestParam("id") Integer id) {
        Integer deleted = hrmSalaryTableConfigService.deleted(id);
        return CommonResult.success("操作成功");
    }

    /**
     * 员工薪资档案
     */

//    @GetMapping("/selectFixedList")
//    public CommonResult<Object> selectFixedList(@RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize) {
//        PageInfo<FixedEmployeeVo> fixedEmployeeVoPageInfo = salaryFixedService.selectFixedList(pageNum, pageSize);
//        return CommonResult.success(fixedEmployeeVoPageInfo);
//    }

    /**
     * 员工薪资档案修改
     *
     * @param hrmSalaryFixed
     * @return
     */
    @PostMapping("/updateEmployeeFixed")
    public CommonResult<Object> updateEmployeeFixed(@RequestBody HrmSalaryFixed hrmSalaryFixed) {
        salaryFixedService.updateEmployeeFixed(hrmSalaryFixed);
        return CommonResult.success("操作成功");
    }


    /**
     * 员工薪资档案调薪回显
     *
     * @param employeeId
     * @return
     */
    @GetMapping("/getEmployeeFixedById")
    public CommonResult<Object> getEmployeeFixedById(@RequestParam("employeeId") Integer employeeId) {
        FixedEmployeeVo employeeFixedById = salaryFixedService.getEmployeeFixedById(employeeId);
        return CommonResult.success(employeeFixedById);
    }


    /**
     * 调薪记录列表
     *
     * @param employeeId
     * @return
     */
    @GetMapping("/selectEmployeeFixedList")
    public CommonResult<Object> selectEmployeeFixedList(@RequestParam("employeeId") Integer employeeId) {
        List<HrmSalaryFixed> hrmSalaryFixeds = salaryFixedService.selectEmployeeFixedList(employeeId);
        return CommonResult.success(hrmSalaryFixeds);
    }

    /**
     * 调薪记录详情
     */
    @GetMapping("/getEmployeeFixedInfoById")
    public CommonResult<Object> getEmployeeFixedInfoById(@RequestParam("id") Integer id) {
        return CommonResult.success(salaryFixedService.getEmployeeFixedInfoById(id));
    }

    /**
     * 调薪记录详情
     */
    @GetMapping("/getEmployeeFixedInfoUpdateById")
    public CommonResult<Object> getEmployeeFixedInfoUpdateById(@RequestParam("id") Integer id) {
        return CommonResult.success(salaryFixedService.getEmployeeFixedInfoUpdateById(id));
    }


    /**
     * 调薪记录编辑
     */
    @PostMapping("/updateEmployeeFixedInfoById")
    public CommonResult<Object> updateEmployeeFixedInfoById(@RequestBody HrmSalaryFixed hrmSalaryFixed) {
        salaryFixedService.updateEmployeeFixedInfoById(hrmSalaryFixed);
        return CommonResult.success("操作成功");
    }


    /**
     * 调薪记录删除
     */
    @GetMapping("/deletedEmployeeFixedInfoById")
    public CommonResult<Object> deletedEmployeeFixedInfoById(@RequestParam("id") Integer id) {
        salaryFixedService.deletedEmployeeFixedInfoById(id);
        return CommonResult.success("操作成功");
    }


    /**
     * @return
     */
    @GetMapping("/selectByEmployeeInfo")
    public CommonResult<Object> selectByEmployeeInfo(@RequestParam("employeeId") Integer employeeId) {
        return CommonResult.success(salaryFixedService.selectByEmployeeInfo(employeeId));
    }


    /**
     * 员工薪资档案定薪
     *
     * @param hrmSalaryFixed
     * @return
     */
    @PostMapping("/insertEmployeeFixedInfo")
    public CommonResult<Object> insertEmployeeFixedInfo(@RequestBody HrmSalaryFixed hrmSalaryFixed) {
        salaryFixedService.insertEmployeeFixedInfo(hrmSalaryFixed);
        return CommonResult.success("操作成功");
    }


    @PostMapping("/updateEmployeeFixedInfo")
    public CommonResult<Object> updateEmployeeFixedInfo(@RequestBody HrmSalaryFixed hrmSalaryFixed) {
        salaryFixedService.updateEmployeeFixedInfo(hrmSalaryFixed);
        return CommonResult.success("操作成功");
    }


//================================================== 定薪模版======================================================================//

    @GetMapping("/firstSelectTableList")
    public CommonResult<Object> firstSelectTableList() {
        List<HrmSalaryTableConfigVo> salaryTableConfigVoList = salaryTemplateService.firstSelectTableList();
        return CommonResult.success(salaryTableConfigVoList);
    }


    @GetMapping("/findSalaryTemplateAll")
    public CommonResult<Object> findSalaryTemplateAll() {
        List<HrmSalaryTemplate> salaryTemplateAll = salaryTemplateService.findSalaryTemplateAll();
        return CommonResult.success(salaryTemplateAll);
    }


    @GetMapping("/selectSalaryTemplateById")
    public CommonResult<Object> selectSalaryTemplateById(@RequestParam("id") Long id) {
        HrmSalaryTemplate salaryTemplate = salaryTemplateService.selectSalaryTemplateById(id);
        return CommonResult.success(salaryTemplate);
    }

    @PostMapping("/insertSalaryTemplate")
    public CommonResult<Object> insertSalaryTemplate(@RequestBody HrmSalaryTemplate hrmSalaryTemplate) {
        salaryTemplateService.insertSalaryTemplate(hrmSalaryTemplate);
        return CommonResult.success("操作成功");
    }

    @PostMapping("/updateSalaryTemplate")
    public CommonResult<Object> updateSalaryTemplate(@RequestBody HrmSalaryTemplate hrmSalaryTemplate) {
        salaryTemplateService.updateSalaryTemplate(hrmSalaryTemplate);
        return CommonResult.success("操作成功");
    }

    @GetMapping("/deleteSalaryTemplateById")
    public CommonResult<Object> deleteSalaryTemplateById(@RequestParam("id") Long id)
    {
        salaryTemplateService.deleteSalaryTemplateById(id);
        return CommonResult.success("操作成功");
    }


    @PostMapping("/generateSalaryRecord")
    public CommonResult<Object> generateSalaryRecord(@RequestBody JSONObject param) {
        param.getInteger("isAccumulation");
        param.getInteger("isProgramme");
        List<Integer> employeeIds = param.getList("employeeIds", Integer.class);
        String string = param.getString("date");
        Integer type = param.getInteger("type");
        salaryRecordService.generateSalaryRecord(type,employeeIds, string);
        return CommonResult.success("生成成功");
    }
//
//    @GetMapping("/selectRecordList")
//    public CommonResult<Object>  selectRecordList(@RequestParam("date") String date){
//
//        return CommonResult.success(salaryRecordService.selectRecordList(date));
//    }


    @PostMapping("/selectRecordListInfo")
    public  CommonResult<Object> selectRecordListInfo(@RequestBody JSONObject param){
        JSONObject jsonObjectPageInfo = salaryRecordService.selectRecordListInfo(param);
        return CommonResult.success(jsonObjectPageInfo);
    }

    @PostMapping("/updateRecordInfo")
    public CommonResult<Object> updateRecordInfo(@RequestBody JSONObject jsonObject){
         salaryRecordService.updateRecordInfo(jsonObject);
        return CommonResult.success("操作成功");
    }


    @PostMapping("/selectRecordUpdateListInfo")
    public  CommonResult<Object> selectRecordUpdateListInfo(@RequestBody JSONObject param){
        JSONObject jsonObjectPageInfo = salaryRecordService.selectRecordUpdateListInfo(param);
        return CommonResult.success(jsonObjectPageInfo);
    }


    @GetMapping("/selectConfirmTable")
    public CommonResult<Object>  selectConfirmTable(@RequestParam("id") Integer id){

        return CommonResult.success(salaryRecordService.selectConfirmTable(id));
    }

    @PostMapping("/updateConfirm")
    public CommonResult<Object>  updateConfirm(@RequestBody JSONObject date){

        return CommonResult.success(salaryRecordService.updateConfirm(date));
    }
//    @GetMapping("/selectConfirmRecordListInfo")
//    public CommonResult<Object>  selectConfirmRecordListInfo(@RequestParam("date") String date){
//
//        return CommonResult.success(salaryRecordService.selectConfirmRecordListInfo(date));
//    }


    @PostMapping("/selectConfirmInfoList")
    public CommonResult<JSONObject> selectConfirmInfoList(@RequestBody JSONObject param){
        return CommonResult.success(salaryRecordService.selectConfirmInfoList(param));
    }



    @PostMapping("/withdraw")
    public CommonResult<Object>  withdraw(@RequestBody JSONObject param){
        Integer ids=param.getInteger("ids");
        return CommonResult.success(salaryRecordService.withdraw(ids));
    }

    @PostMapping("/sendConfirm")
    public CommonResult<Object>  sendConfirm(@RequestBody JSONObject param){
    Integer ids=param.getInteger("ids");
        return CommonResult.success(salaryRecordService.sendConfirm(ids));
    }

    @GetMapping("/allSendConfirm")
    public CommonResult<Object>  allSendConfirm(@RequestParam("recordId") Integer recordId){
        return CommonResult.success(salaryRecordService.allSendConfirm(recordId));
    }

    @GetMapping("/allWithdraw")
    public CommonResult<Object>  allWithdraw(@RequestParam("recordId") Integer recordId){
        return CommonResult.success(salaryRecordService.allWithdraw(recordId));
    }

    @GetMapping("/selectEmployeeConfirmInfo")
    public CommonResult<Object>  selectEmployeeConfirmInfo(@RequestParam("id") Integer id){
        return CommonResult.success(salaryRecordService.selectEmployeeConfirmInfo(id));
    }

    @GetMapping("/historySalaryList")
    public CommonResult<Object>  historySalaryList(@RequestParam("date") String date){
        return CommonResult.success(salaryRecordService.historySalaryList(date));
    }

    @PostMapping("/historySalaryInfo")
    public CommonResult<Object> historySalaryInfo(@RequestBody JSONObject jsonObject){
        JSONObject jsonObject1 = salaryRecordService.historySalaryInfo(jsonObject);
        return CommonResult.success(jsonObject1);
    }

    @GetMapping("/updateRemark")
    public CommonResult<Object>  updateRemark(@RequestParam("remark") String remark,@RequestParam("id")Integer id){
        return CommonResult.success(salaryRecordService.updateRemark(remark,id));
    }


    @GetMapping("/removeSalary")
    public CommonResult<Object>  removeSalary(@RequestParam("recordId")Integer  recordId){
        return CommonResult.success(salaryRecordService.removeSalary(recordId));
    }


















































//   计薪标准==================================================================================================================================
//    /**
//     * 计薪标准新增
//     */
//    @PostMapping("/insertSalaryStandard")
//    public  CommonResult<Object> insertSalaryStandard(@RequestBody HrmSalaryStandard hrmSalaryStandard) {
//        hrmSalaryStandardService.insertSalaryStandard(hrmSalaryStandard);
//        return CommonResult.success("操作成功");
//    }
//
//    /**
//     * 计薪标准修改
//     */
//    @PostMapping("/updateSalaryStandard")
//    public  CommonResult<Object> updateSalaryStandard(@RequestBody HrmSalaryStandard hrmSalaryStandard) {
//        hrmSalaryStandardService.updateSalaryStandard(hrmSalaryStandard);
//        return CommonResult.success("操作成功");
//    }
//
//    /**
//     * 计薪标准列表
//     */
//    @GetMapping("/selectSalaryStandardByPage")
//    public  CommonResult<Object> selectSalaryStandardByPage(@RequestParam("pageNum")Integer pageNum,@RequestParam("pageSize")Integer pageSize) {
//        PageInfo<HrmSalaryStandard> hrmSalaryStandardPageInfo = hrmSalaryStandardService.selectSalaryStandardByPage(pageNum, pageSize);
//        return CommonResult.success(hrmSalaryStandardPageInfo);
//    }
//
//    /**
//     * 计薪标准下拉
//     */
//    @GetMapping("/salaryStandardBySelect")
//    public CommonResult<Object> salaryStandardBySelect(){
//        List<JSONObject> jsonObjects = hrmSalaryStandardService.salaryStandardBySelect();
//        return CommonResult.success(jsonObjects);
//    }
}
